package com.yifeng.repo.controller.fadada.web;

import com.yifeng.repo.controller.fadada.signature.FadadaSignatureManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.ServletContextInitializer;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

/**
 * Created by daibing on 2024/12/04.
 */
@Slf4j
public class FadadaServletRegistrar implements ServletContextInitializer {
    private final String adminApiPrefix;
    private final FadadaSignatureManager fadadaSignatureManager;

    public FadadaServletRegistrar(String adminApiPrefix, FadadaSignatureManager fadadaSignatureManager) {
        this.adminApiPrefix = adminApiPrefix;
        this.fadadaSignatureManager = fadadaSignatureManager;
    }

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        FadadaServlet servlet = new FadadaServlet(fadadaSignatureManager);
        ServletRegistration.Dynamic registration = servletContext.addServlet("FadadaServlet", servlet);
        registration.addMapping(adminApiPrefix + "/*");
        registration.setLoadOnStartup(1);
        log.info("yfcloud controller open admin api success: fadada");
    }
}
